#ifndef RECENT_DOCS_FEATURE_H
#define RECENT_DOCS_FEATURE_H

#include "feature.h"
#include "../widgets/checkbox.h"
#include "../widgets/button.h"
#include "../widgets/clickable_label.h"

#include "../../model/core_io.h"
#include "../../model/player.h"

class RecentDocsFeature: public Feature,
private ClickableLabelListener
{
public:
    RecentDocsFeature(int _id, Engine* _engine, int _x, int _y, int _w, int _h,
                      ControllerProxy* _cProxy, MainWidget* _mw)
                          :Feature(_id, _engine, _mw, _cProxy, _x, _y, _w, _h)
    {
        noDocs = new Label( this, engine, "No recent items", 20, 30, 150, 20 );
        AddChild( noDocs );

        for( int i=0; i<15; i++ )
        {
            l[i] = new ClickableLabel( this, engine, "Recent item", 20, 30 + 40 * i, w - 40, 20 );
            l[i]->AddClickableListener( this );
            AddChild( l[i] );
        }
    }
    virtual ~RecentDocsFeature(){ }

    virtual void doShow( void )
    {
        if( cProxy->postOpenAction == 0 )
        {   // recent playlists
            CoreIO::docsManager->getRecentPlaylists( sl );
        }
        else
        {   // recent songs
            CoreIO::docsManager->getRecentSongs( sl );
        }

        int sz = 15;
        if( sl.size() < 15 ) sz = sl.size();

        if( sz > 0 )
        {
            for( int i=0; i<sz; i++ )
            {
                l[i]->SetText( sl[i] );
                l[i]->SetX( 20 );
            }

            for( int i=sz; i<15; i++ )
            {
                l[i]->SetX( -1000 );
            }

            noDocs->SetX( -1000 );
        }
        else
        {
            for( int i=0; i<15; i++ )
            {
                l[i]->SetX( -1000 );
            }
            noDocs->SetX( 20 );
        }

        visible = true;
        paintEnabled = true;
        Showed();
    }

    virtual void doHide( void )
    {
        visible = false;
        Hidden();
    }

private:
    ClickableLabel* l[15];
    Label* noDocs;
    QStringList sl;

    virtual void OnClick( ClickableLabel* sender )
    {
        QString filename = sender->GetText();
        Player::GetInstance()->Open( filename );
        cProxy->stringParam = filename;

        QFileInfo fi( filename );
        if( fi.suffix() == "mps" )
        {
            cProxy->UnloadRequest( ControllerProxy::PLAYER_FEATURE );
        }
        else
        {
            cProxy->UnloadRequest( ControllerProxy::EDIT_SONG_FEATURE );
        }
    }

};

#endif // RECENT_DOCS_FEATURE_H
